using System;
using System.Collections;
using System.Collections.Generic;
using UintyEngineExtensions;
using UnityEngine;

public class MouseFollower : MonoBehaviour
{
    [Serializable]
    public abstract class  ModiferPosition
    {
        public abstract Vector3 Modifer(Vector3 pos);

    }
    
    [Serializable]
    class SnapInt: ModiferPosition
    {
        public override Vector3 Modifer(Vector3 pos)
        {
            var y = pos.y;
            pos = pos.Round();
            pos.y = y;
            return pos;
        }
    }
// [Serializable]
//     class Lerp:ModiferPosition
//     {
//         [SerializeField] private float _speed =15f;
//         public override Vector3 Modifer(Vector3 pos)
//         {
//             var lerpPos= Vector3.Lerp(transform.position, pos, Time.deltaTime * _speed);
//             lerpPos.y = pos.y;
//             return lerpPos;
//         }
//     }

    [SerializeField] private float _speed =15f;
    [SerializeReference] private List<ModiferPosition> _modifersList;
    
    void Update()
    {
        var pos = Mouse3D.GetMouseWorldPosition();
        foreach (var modiferPosition in _modifersList)
        {
            pos = modiferPosition.Modifer(pos);
        }
        SetPosition(pos);
    }

    public virtual void SetPosition(Vector3 pos)
    {
        var lerpPos= Vector3.Lerp(transform.position, pos, Time.deltaTime * _speed);
        lerpPos.y = pos.y;
        transform.position = lerpPos;
    }
    private void OnDrawGizmos()
    {
        var mousePos = Mouse3D.GetMouseWorldPosition();
        Gizmos.color = Color.red;
        Gizmos.DrawSphere(mousePos, 0.1f);
    }
}
